// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Quran.java

package mForms;

import app.*;
import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.midlet.MIDlet;
import ui.*;

// Referenced classes of package mquran:
//            splashQuran, QuranCanvas, MenuBarQuran, LockedCanvas

public class MainFormss extends MIDlet
    implements PlayerListener, PageListener
{

    public static MainFormss instance() {
        return me;
    }

    public String lang = "ar";
    private IndexMenu mnuIndex;
    //private AgentDrawer agent;
    IndexMenu im;

    public MainFormss()
    {
        locked = true;
        judul = null;
        KEYDOWN = -2;
        TRIGHT = -4;
        TLEFT = -3;
        BrowserCanvas.KEYCENTER = -5;
        BrowserCanvas.KEYUP = -1;
        BrowserCanvas.KEYDOWN = -2;
        BrowserCanvas.TRIGHT = -4;
        BrowserCanvas.TLEFT = -3;
        BrowserCanvas.KEYSOFTLEFT = -6;
        BrowserCanvas.KEYSOFTRIGHT = -7;
        me = this;
    }

    public final void startApp()
    {
        if(display == null)
        {
            display = Display.getDisplay(this);
            display.setCurrent(new splashQuran());
            pages = new Vector();
            browser = new BrowserCanvas(display, this);
            agent = new AgentWorker();
          
            Runnable r = new Runnable() {

                public void run()
                {
                    try
                    {
                        //Thread.sleep(2000L);
                        Thread.sleep(300L);
                    }
                    catch(InterruptedException ex)
                    {
                        ex.printStackTrace();
                    }

                    showPage("surah.txt", null);

                }
            };
            (new Thread(r)).start();
        }
    }

  

    public void showIndex() {
        //if(im==null)
            im = new IndexMenu(me);
        
        display.setCurrent(im);
    }


    public void showMenuUtama()
    {
        if(pagemnu == null)
            pagemnu = new mMenu(browser, this);
        display.setCurrent(browser);
        judul = "menu";
        browser.showPage(pagemnu, 0);
    }

    public static Displayable getCurrent()
    {
        return display.getCurrent();
    }

    /*
    public void openIndex()
    {
        qurancanvas = new QuranCanvas(display, this);
        qurancanvas.init();
        display.setCurrent(qurancanvas);
    }

    public void openPendahuluan()
    {
        qurancanvas = new QuranCanvas(display, this);
        qurancanvas.init();
        display.setCurrent(qurancanvas);
        qurancanvas.openSurah(115);
    }
     * 
     */

    public void exitMIDlet()
    {
        display.setCurrent(null);
        exit();
    }

    public final void pauseApp()
    {
    }

    public final void destroyApp(boolean flag1)
    {
    }

    public static void exit()
    {
        me.destroyApp(true);
        me.notifyDestroyed();
        me = null;
    }

    public void playerUpdate(Player player1, String s, Object obj)
    {
    }

    public static void show(Displayable disp)
    {
        display.setCurrent(disp);
    }

    /*
    public void onMenu(MenuBarQuran menuBar, int selected, String caption)
    {
        if(caption.equals("Menu Utama"))
            showMenuUtama();
        else
        if(caption.equals("Pendahuluan"))
            showPage("pendahuluan.txt", null);
        else
        if(caption.equals("Bantuan"))
            showPage("bantuan.txt", null);
        else
        if(caption.equals("Tentang"))
            showPage("tentang.txt", null);
    }
     *
     */

    public static String getMCC()
    {
        String out = "";
        try
        {
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("phone.mcc");
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("com.nokia.mid.countrycode");
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("com.sonyericsson.net.mcc");
            if((out == null || out.equals("null") || out.equals("")) && (out == null || out.equals("null") || out.equals("")))
                out = System.getProperty("mcc");
        }
        catch(Exception e)
        {
            return out != null ? out : "";
        }
        return out != null ? out : "";
    }

    public static String getMNC()
    {
        String out = "";
        try
        {
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("phone.mnc");
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("com.nokia.mid.networkid");
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("com.sonyericsson.net.mnc");
            if(out == null || out.equals("null") || out.equals(""))
                out = System.getProperty("mnc");
        }
        catch(Exception e)
        {
            return out != null ? out : "";
        }
        return out != null ? out : "";
    }

    public void onMenu(Page src, int menu, String caption)
    {
        switch(menu) {
            case 0:
                showIndex();
                break;
            case 1:
                exitMIDlet();
                break;
        }
    }

    public void showPage(String url, Integer top)
    {
        System.out.println("====>>showpage= "+url+" top="+top );
        mPage p = new mPage(browser, url, this);
        System.out.println("=======>>URL : " + url);
        if(browser.getPage() != null)
            pages.addElement(browser.getPage());
        

        display.setCurrent(browser);
        browser.judulContent = judul;
        browser.showPage(p, 0);
        cur_url = "/data/" + url;
        
//        agent.draw(cur_url, p);
        agent.addQueue(cur_url, p, top);
    }

    public void onItemClick(Page src, Element element, int index)
    {
        System.err.println("index : " + index);
        if(element instanceof Hyperlink)
        {
            Hyperlink new_name = (Hyperlink)element;
            judul = new_name.url;
            if(new_name.url.startsWith("http"))
                try
                {
                    platformRequest(new_name.url);
                }
                catch(ConnectionNotFoundException e)
                {
                    e.printStackTrace();
                }
            else
                showPage(new_name.url, null);
        } else
        if(element instanceof MenuElement)
        {
            MenuElement new_name = (MenuElement)element;
            judul = new_name.url;
            if(new_name.url.equals("exit"))
                exitMIDlet();
            /*
            else
            if(new_name.url.equals("index_quran"))
                openIndex();
             *
             */
            else
                showPage(new_name.url, null);
        } else
        if(element instanceof ImageHypElement)
        {
            ImageHypElement new_name = (ImageHypElement)element;
            judul = new_name.url;
            if(new_name.url.startsWith("http")) {
                try
                {
                    platformRequest(new_name.url);
                }
                catch(ConnectionNotFoundException e)
                {
                    e.printStackTrace();
                }
            } else
            if(new_name.url.startsWith("sms")) {
                int p1 = new_name.url.indexOf("|");
                int p2 = new_name.url.indexOf("|",p1+1);

                String keyword = new_name.url.substring(p1+1, p2);

                //p1 = new_name.url.indexOf("|",p2+1);
                p1 = p2;
                p2 = new_name.url.indexOf(">", p1+1);

                String nmr = new_name.url.substring(p1+1, p2);

                showPage(keyword+".txt", null);

                browser.showing_tnc = true;

                //Timer timer = new Timer();
                //timer.schedule(new SMSSend(keyword,nmr,pages,browser), 50);
                Thread t = null;
                //t = new Thread(new SMSSend(keyword, nmr,MainFormss.me));
//                t = new Thread(new SMSSend(keyword, nmr,pages,browser));
                t.start();


            }
            else
                showPage(new_name.url, null);
        }
    }

    public void onSoftRightMenu(Page page)
    {
        agent.stopAll();
        System.out.println("page size : " + pages.size());
        if(pages.size() > 0)
        {
            if(pages.size() == 1) {
                browser.judulContent = "menu";
            } else {
                browser.judulContent = "xxx";
            }
            System.out.println("judul : " + browser.judulContent);
            int last = pages.size() - 1;
            Page p = (Page)pages.elementAt(last);
            pages.removeElementAt(last);
            browser.showPage(p, 0);
        } else
        {
            showIndex();
        }
    }

    public void onSoftLeftMenu(Page page, int menu)
    {
        agent.stopAll();
        System.out.println("Doahusna.onSoftLeftMenu():" + pages.size());
        switch(menu)
        {
            case 0: // '\0'
                //showPage("pendahuluan.txt", null);
                break;
            case 1: // '\0'
                exitMIDlet();
                break;
        }
        
        if(pages.size() == 0)
            browser.judulContent = "menu";
        else
            browser.judulContent = "xxx";
    }

    public void onMessageBox(int i)
    {
    }

    static MainFormss me;
    public static BrowserCanvas browser;
    AgentWorker agent;
    mMenu pagemnu;
    langMenu langmnu;
    Vector pages;
    private MenuBar menuIndex;
    private MenuBar menuDepan;
    private MenuBar menuContent;
    public static Display display;
    public static final int KEYSOFTRIGHT = -7;
    public static final int KEYCENTER = -5;
    public static final int KEYUP = -1;
    public static int KEYDOWN = 0;
    static int TRIGHT;
    static int TLEFT;
    static final int KEYSOFTLEFT = -6;
    static final String CAP_EXIT = "Keluar";
    public static final String CAP_OPEN = "Buka";
    public static final String CAP_INDEX = "Index Surah";
    public static final String CAP_MENU = "Menu Utama";
    public static final String CAP_SAVEBOOKMARK = "Simpan Bookmark";
    public static final String CAP_GOTO_AYAT = "Ke Ayat";
    static final String CAP_GOTOBOOKMARK = "Buka Bookmark";
    public static final String CAP_GOTOSTART = "Awal";
    public static final String CAP_GOTOEND = "Akhir";
    public static final String CAP_INTRO = "Pendahuluan";
    public static final String CAP_BANTUAN = "Bantuan";
    public static final String CAP_ABOUT = "Tentang";
    private boolean locked;
    private String judul;
    private String cur_url;

    void goArabic() {
        this.lang = "ar";
        if(mnuIndex==null)
            mnuIndex = new IndexMenu(me);

        display.setCurrent(mnuIndex);
    }

    void goEnglish() {
        this.lang = "en";
        if(mnuIndex==null)
            mnuIndex = new IndexMenu(me);

        display.setCurrent(mnuIndex);
    }
}
